package cn.flashk.controls {
	import com.skins.Skin;
	
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;
	
	import cn.flashk.controls.managers.DefaultStyle;
	import cn.flashk.controls.managers.SkinLoader;
	import cn.flashk.controls.managers.SkinManager;
	import cn.flashk.controls.managers.SourceSkinLinkDefine;
	import cn.flashk.controls.modeStyles.ButtonMode;
	import cn.flashk.controls.modeStyles.ButtonStyle;
	import cn.flashk.controls.skin.ActionDrawSkin;
	import cn.flashk.controls.skin.CheckBoxSkin;
	import cn.flashk.controls.skin.sourceSkin.CheckBoxSourceSkin;

	/**
	 * CheckBox 组件显示一个小方框，该方框内可以有选中标记。 CheckBox 组件还可以显示可选的文本标。
	 *
	 * <p>CheckBox 组件为响应鼠标单击将更改其状态，或者从选中状态变为取消选中状态，或者从取消选中状态变为选中状态。 CheckBox 组件包含一组非相互排斥的 true 或 false 值。</p>
	 *
	 * @author flashk
	 */
	public class CheckBox extends ToggleButton {
		public function CheckBox(skinID:String = ""){
			super(skinID);
			label = "多选";
			styleSet[ButtonStyle.TEXT_COLOR] = DefaultStyle.checkBoxTextColor;
			styleSet[ButtonStyle.TEXT_OVER_COLOR] = DefaultStyle.checkBoxTextOverColor;
			styleSet[ButtonStyle.TEXT_DOWN_COLOR] = DefaultStyle.checkBoxTextColor;
			tf.align = TextFormatAlign.LEFT;
			txt.setTextFormat(tf)
		}

		override public function setDefaultSkin():void {
			setSkin(CheckBoxSkin);
		}

		override public function setSourceSkin():void {
			setSkin(SkinLoader.getClassFromSkinFile(SourceSkinLinkDefine.CHECK_BOX));
		}

		override public function setLoaderSkin(skinID:String = ""):void {
			var sous:CheckBoxSourceSkin = new CheckBoxSourceSkin(_skinID);
			sous.init(this, styleSet, null);
			skin = sous;
		}

		override public function setSkin(Skin:Class):void {
			if (SkinManager.isUseDefaultSkin == true){
				skin = new Skin();
				ActionDrawSkin(skin).init(this, styleSet);
			} else {
				var sous:CheckBoxSourceSkin = new CheckBoxSourceSkin();
				sous.init(this, styleSet, Skin);
				skin = sous;
			}
		}

		override public function updateSkin():void {
			super.updateSkin();
			styleSet[ButtonStyle.TEXT_COLOR] = DefaultStyle.checkBoxTextColor;
			styleSet[ButtonStyle.TEXT_OVER_COLOR] = DefaultStyle.checkBoxTextOverColor;
			styleSet[ButtonStyle.TEXT_DOWN_COLOR] = DefaultStyle.checkBoxTextColor;
		}

		override public function set label(value:String):void {
			super.label = value;
			txt.width = txt.textWidth + 10;
		}
	}
}